/**
 * 
 */
package se.cirrus.base.com;


/**
 * @author Winquman
 *
 */
public class CommunicationState implements Comparable<CommunicationState> {

	public static final int ERROR = -30;
	public static final int CONNECTION_LOST = -10;
	public static final int UNINITIALIZED = 0;
	public static final int CLOSED = 10;
	public static final int CONNECTING = 20;
	public static final int NEGOTIATING = 22;
	public static final int OPEN = 30;
	
	private int status;
	
	/**
	 * 
	 */
	public CommunicationState() {
		status = 0;
	}

	@Override
	public int compareTo(CommunicationState arg0) {
		
		return status - arg0.getStatus();
	}
	
	public boolean equals(CommunicationState arg0) {
		if(arg0.getStatus() == status)
			return true;
		else
			return false;
	}
	
	/**
	 * Is this connection alive?
	 * @return
	 */
	public boolean ok() {
		if(status > 29)
			return true;
		else
			return false;
	}
	
	/**
	 * Is this connection in an error state?
	 * @return
	 */
	public boolean error() {
		if(status < 0)
			return true;
		else
			return false;
	}
	
	public int getStatus() {
		return status;
	}

}
